<?php
/** "Abstract" Delete action: can not be executed, only subclassed with override of verifyArguments()
 *
 *
 */
class Yz_Action_Delete
    extends Yz_Action_Abstract
{


    /************************************
     *        Protected methods         *
     ************************************/

    /** Verify arguments before building query
     *      prevent deletion without sensible arguments
     *  @return this
     */
    protected function verifyArguments()
    {
        debug();
        throw new Yz_Action_Exception("Forbidden to Delete without argument verification");
    }

    /**
     *  Common Insert statement creator:
     *      the common part of statement
     *  @return Yz_SQL_Statement_Insert
     */
    protected function buildStatement()
    {
        debug();
        $this->inspectModel();
        return Yz_SQL_Statement_Delete::create()
            ->delete(key($this->tables) . '.*')
            ->from(current($this->tables), key($this->tables))
        ;
    }



    /** Inspect a model and determine what (fields) and from where (tables) will be selected
     *  @param Yz_Model_Interface|null $model, null means the Action's model
     *  @return Yz_Array fields
     */
    protected function inspectModel(Yz_Model_Interface $model=null)
    {
        debug();

        if (! $model) {
            $model = $this->model;
            $this->tables[$model->getName()] = $model->getSourceName();
        } else {
            throw new Yz_Action_Exception("Can not Delete from non-default table");
        }

        return $this;
    }

}
